<template>
    <div class="segment-content-box">
        <a-tabs v-model:activeKey="tabsModeValue" >
            <a-tab-pane key="审查项目" tab="审查项目"></a-tab-pane>
            <a-tab-pane key="文件信息" tab="文件信息"></a-tab-pane>
        </a-tabs>
        <a-collapse v-model:activeKey="activeKeyArr" class="tabs-collapse-box" v-if="tabsModeValue == '文件信息'">
            <a-collapse-panel key="1" header="药品经营企业技术审评审核件" class="collapse-panel-head-l380">
                <a-form layout="inline" style="margin-bottom:10px">
                    <a-form-item >
                        <a-button class="blue-btn" type="primary" @click="generateRecord('技术审查报告','技术审查报告')">生成记录</a-button>
                    </a-form-item>
                </a-form>
                <commpVxeTable
                    :key="refreshTable"
                    :config="reportConfig" 
                    :columns="reportColumns"
                    :formItem="[]" 
                    :adaptiveHeight="true"
                > 
                    <template v-slot:fwjccmc_slots="{row}" data-desc="自定操作栏">
                        <span>{{ row.fwjxsmc }}{{ row.fwjlx }}</span>
                    </template>
                    <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                        <a-form layout="inline" class="search-form" >
                            <a-form-item class="vxe-table-box-w">
                                <a-button class="blue-btn" type="primary" @click="viewClick(row)" >查看</a-button>
                            </a-form-item>
                            <a-form-item>
                                <a-button class="blue-btn dMould-btn" type="primary" @click="producerMould(row,'技术审查报告')" >选择模板</a-button>
                            </a-form-item>
                            <a-form-item v-if="editMode == '服务端模式'">
                                <!-- 服务端编辑 -->
                                <a-button class="blue-btn" type="primary" @click="serverEdit(row)" >编辑</a-button>
                            </a-form-item>
                            <a-form-item class="vxe-table-box-w" v-if="row.fwjlx !== '.pdf' && editMode == '客户端模式'">
                                <a-button class="blue-btn" type="primary" @click="producerEdit(row,'技术审查报告')" >编辑</a-button>
                            </a-form-item>
                            <a-form-item  v-if="row.fwjlx == '.pdf' && editMode == '客户端模式'">
                                    <a-button class="blue-btn dMould-btn" type="primary" @click="againEdit(row,'技术审查报告')" >重新编辑</a-button>
                            </a-form-item>
                            <a-form-item class="vxe-table-box-w">
                                <a-button class="red-btn" type="primary" @click="producerDelete(row,'技术审查报告')" >删除</a-button>
                            </a-form-item>
                            <a-form-item class="vxe-table-box-w">
                                <a-upload style="display: inline-block;" :beforeUpload="producerBeforeUpload" action="" @change="producerUpload($event,row)">
                                    <a-button class="blue-btn" type="primary">上传</a-button>
                                </a-upload>
                            </a-form-item>
                            <a-form-item class="vxe-table-box-w">
                                <a-button class="blue-btn" type="primary" @click="producerDownload(row,'技术审查报告')" >下载</a-button>
                            </a-form-item>
                        </a-form>
                    </template>
                </commpVxeTable>
            </a-collapse-panel>
            <!-- <a-collapse-panel key="2" header="审评整改材料要求" class="collapse-panel-head-l255">
                <a-form layout="inline" style="margin-bottom:10px">
                    <a-form-item >
                        <a-button class="blue-btn" type="primary" @click="generateRecord('审评整改材料要求','审评整改材料要求')">生成记录</a-button>
                    </a-form-item>
                </a-form>
                <commpVxeTable
                    :key="refreshTable"
                    :config="rectificationConfig" 
                    :columns="rectificationColumns"
                    :formItem="[]" 
                    :adaptiveHeight="true"
                > 
                    <template v-slot:fwjccmc_slots="{row}" data-desc="自定操作栏">
                        <span>{{ row.fwjxsmc }}{{ row.fwjlx }}</span>
                    </template>
                    <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                        <a-form layout="inline" class="search-form" >
                            <a-form-item class="vxe-table-box-w">
                                <a-button class="blue-btn" type="primary" @click="viewClick(row)" >查看</a-button>
                            </a-form-item>
                            <a-form-item v-if="editMode == '服务端模式'">
                                <a-button class="blue-btn" type="primary" @click="serverEdit(row)" >编辑</a-button>
                            </a-form-item>
                            <a-form-item class="vxe-table-box-w" v-if="row.fwjlx !== '.pdf' && editMode == '客户端模式'">
                                <a-button class="blue-btn" type="primary" @click="producerEdit(row,'审评整改材料要求')" >编辑</a-button>
                            </a-form-item>
                            <a-form-item  v-if="row.fwjlx == '.pdf' && editMode == '客户端模式'">
                                    <a-button class="blue-btn dMould-btn" type="primary" @click="againEdit(row,'审评整改材料要求')" >重新编辑</a-button>
                            </a-form-item>
                            <a-form-item class="vxe-table-box-w">
                                <a-button class="red-btn" type="primary" @click="producerDelete(row,'审评整改材料要求')" >删除</a-button>
                            </a-form-item>
                            <a-form-item class="vxe-table-box-w">
                                <a-upload style="display: inline-block;" :beforeUpload="producerBeforeUpload" action="" @change="producerUpload($event,row)">
                                    <a-button class="blue-btn" type="primary">上传</a-button>
                                </a-upload>
                            </a-form-item>
                            <a-form-item class="vxe-table-box-w">
                                <a-button class="blue-btn" type="primary" @click="producerDownload(row,'审评整改材料要求')" >下载</a-button>
                            </a-form-item>
                        </a-form>
                    </template>
                </commpVxeTable>
            </a-collapse-panel> -->
            <a-collapse-panel key="3" header="技术审查报告流程" class="collapse-panel-head-l255">
                <a-form layout="inline" style="margin-bottom:10px">
                    <a-form-item >
                        <a-button class="blue-btn" type="primary" @click="generateRecord('发起流程',1)">发起流程</a-button>
                    </a-form-item>
                </a-form>
                <commpVxeTable
                    :key="refreshTable"
                    ref="headmanVxeTable"
                    :config="flowJkPageConfig" 
                    :columns="flowJkPagecolumnsVxe" 
                    :formItem="[]"
                    :adaptiveHeight="true"
                >
                    <template v-slot:name_fslsj="{row}" data-desc="自定操作栏">
                        <span>{{ timeProcessing(row.fslsj) }}</span>
                    </template>
                    <template v-slot:name_fblzt="{row}" data-desc="自定操作栏">
                        <span style="color: rgb(211, 51, 51);">{{ row.fblzt }}</span>
                    </template>
                    
                    <template v-slot:name_ffssj="{row}" data-desc="自定操作栏">
                        <span>{{ row.ffssj }}</span>
                    </template>
                    <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                        <a-form layout="inline" class="search-form" >
                            <a-form-item v-if="row.fblzt == '待办'">
                                <a-button class="blue-btn" type="primary" @click="expertProcessReturn(row)" >退回</a-button>
                            </a-form-item>
                            <a-form-item v-if="row.fblzt == '待办'">
                                <a-button class="blue-btn" type="primary" @click="expertProcesstErmination(row,'专家流程')" >终止</a-button>
                            </a-form-item>
                            <!-- <a-form-item>
                                <a-button class="blue-btn" type="primary" @click="goHandleClick(row)" >去办理</a-button>
                            </a-form-item> -->
                        </a-form>
                    </template>
                </commpVxeTable>
            </a-collapse-panel>
        </a-collapse>
        <div style="width: 100%;" v-show="tabsModeValue == '审查项目'">
            <a-row style="width: 100%;">
                <a-col :span="5">
                    <div class="tree-left-box">
                        <a-tree
                            v-model:checkedKeys="treeCheckedKeys"
                            :autoExpandParent="true"
                            :defaultExpandAll="true"
                            :selectedKeys="selectedKeys"
                            @select="treeSelect"
                            :tree-data="treeData"
                        />
                    </div>
                    
                </a-col>
                <a-col :span="19">
                    <div class="tree-right-box">
                        <commpVxeTable
                            :key="reviewItemsRefresh"
                            :config="reviewItemsConfig" 
                            :columns="reviewItemsColumns" 
                            :formItem="reviewItemsFormItem"
                            @tableUpdated="tableUpdated"
                            ref="reviewItemsRef"
                        >
                            <template v-slot:querButton="{row}">
                                <vxe-button type="text" status="primary" content="查询所有审查结论缺陷" @click="queryAllSfqx"></vxe-button>
                                <vxe-button style="margin-left: 15px;" type="text" status="primary" content="查询所有技术审查结论缺陷" @click="queryAllJsscqx"></vxe-button>
                            </template>
                            <template v-slot:name_ftype7="{row}" data-desc="自定操作栏">
                                <div style="display: flex;height: 48px;align-items: center;">
                                    <i @click="lookOverContent(row)" style="color: #5ca3e5;" class="vxe-icon-search"></i>
                                    <span style="padding-left: 8px;">{{row.ftype7}}</span>
                                </div>
                            </template>
                            <template v-slot:name_fjcjl="{row}" data-desc="自定操作栏">
                                <span >{{ row.fjcjl }}</span>
                            </template>
                            <template v-slot:name_fscjl="{row}" data-desc="自定操作栏">
                                <span>{{ row.fscjl }}</span>
                            </template>
                            <template v-slot:name_fgjqk="{row}" data-desc="自定操作栏">
                                <div
                                    @click="reviewRecordsClick(row,false)" 
                                    style="width: 100%; height: 48px; display: flex; align-items: center;" 
                                    
                                >
                                <!-- v-if="reviewRecordsId !== row.id || !reviewRecordsId" -->
                                    <span>{{ row.fgjqk }}</span>
                                </div>
                                <!-- <div style="background-color: #fff;">
                                    <vxe-textarea
                                        class="review-records-box"
                                        ref="userNameInput"
                                        v-if="reviewRecordsId && reviewRecordsId == row.id"
                                        @focus="reviewRecordsFocusEvent"
                                        @blur="reviewRecordsBlurEvent(row)"
                                        placeholder="请输入技术审查内容"
                                        v-model:value="row.fgjqk"
                                        :autosize="{ minRows: 2, maxRows: 30 }">
                                    </vxe-textarea>
                                </div> -->
                                
                            </template>
                            <template v-slot:name_fgjshjl="{row}" data-desc="自定操作栏">
                                <a-select
                                v-model:value="row.fgjshjl"
                                :options="optionsData"
                                style="width: 105px"
                                @change="selectFgjshjlChange($event,row)"
                                ></a-select>
                                <!-- <compSelector
                                    :key="selectItem"
                                    :compName="'name'+row.id"
                                    :width="105"
                                    v-model="row.fgjshjl"
                                    :compType="typeSelect"
                                    :defaultValue="row.fgjshjl"
                                    :options="{
                                        data:optionsData,
                                        dataType:{
                                            label:'itemText',
                                            value:'itemValue',
                                        }
                                    }"
                                    @selectHandleChange="selectFgjshjlChange($event,row)"
                                /> -->
                            </template>

                        </commpVxeTable>
                    </div>
                </a-col>
            </a-row>
        </div>
    
        
        <a-modal
            title="查看"
            :visible="fcontentVisible"
            @ok="fcontentVisible = false"
            @cancel="fcontentVisible = false"
        >
            <p>
                <span style="font-weight: 600;">章节：</span>
                <span>{{ fcontentObj.ftype3 }}</span>
            </p>
            <p>
                <span style="font-weight: 600;">章节标题：</span>
                <span>{{ fcontentObj.ftype4 }}</span>
            </p>
            <p>
                <span style="font-weight: 600;">条款：</span>
                <span>{{ fcontentObj.ftype5 }}</span>
            </p>
            <p>
                <span style="font-weight: 600;">项目类型：</span>
                <span>{{ fcontentObj.ftype6 }}</span>
            </p>

            <p>
                <span style="font-weight: 600;">条款号：</span>
                <span>{{ fcontentObj.ftype7 }}</span>
            </p>
            <p>
                <span style="font-weight: 600;">审查内容：</span>
                <span>{{ fcontentObj.fcontent1 }}</span>
            </p>
        </a-modal>
        <a-modal
            title="修改技术审查内容"
            :visible="examinationVisible"
            @ok="examinationOk"
            @cancel="examinationVisible = false"
            :width="720"
        >
            <a-form class="">
                <a-form-item label="条款">
                    <span>{{ fgjqkContent.ftype5 }}</span>
                </a-form-item>
                <a-form-item label="技术审查内容">
                    <a-textarea
                        ref="userNameInput"
                        placeholder="请输入技术审查内容"
                        v-model:value="fgjqkContent.fgjqk"
                        :autosize="{ minRows: 4, maxRows: 30 }">
                    </a-textarea>
                </a-form-item>
            </a-form>
                
        </a-modal>
        <serverEditing ref="serverEditingRef" @refreshChange="manualSuccess"/>
        <serverEditingView ref="serverEditingViewRef" @refreshChange="$event=>{}"/>
        <selectTemplate ref="selectTemplateRef" @selectTemplateComplete="selectTemplateComplete"/>
    </div>
</template>
<script>
import serverEditingView from '@/components/comp-model-series/server-editing-view'
import serverEditing from '@/components/comp-model-series/server-editing.vue'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import assessCheckApi from './service/api'
import compSelector from '@/components/compSelector/compSelector.vue'
import { 
    initJsscbgFlow,
    getDictListByDictCodeServe,
    getLocalFileByIdServe,
    deletemodelByIdServe, 
    getFileTypeServe, 
    initWjjlServe, 
    queryListYwflServe, 
    spcyRsYwzdxxAddServe,
    spcyRsYwzdxxDeleteServe,
    getDefectRecordMapServe,
    addBatchIdeaServe,
    handlingOpinionsListServe,
    addServe,
    editServe,
    queryJcxmTreeTypeServe,
    queryJcxmListServe,
    ocalityPostAction,
    updateSqsxJcxmServe,
    getLocalFileById,
    deleteBatchIdeaServe,
    uploadMoreTypeFileServe,
    uploadPdfFileById,
    deleteFileByIdServe,
    queryYwzdYwflContent,
    getComprehensiveConclusionsMap,
    againEditPdfFile,
    selectWjmbServe,
    updateYpltJcxm,
    returnSpBzFlow,
    endFlowJob
 } from './service/index'
import blobType from '@/common/blobType'
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import YchConstant from "@/api/YchConstant";
export default {
    components:{
        serverEditing,
        commpVxeTable,
        compSelector,
        serverEditingView,
    },
    props:{
        addEdittechnicalReview:{
            type:[Array,Object],
            default: () => {},
            required:false
        },
    },
    watch:{
        addEdittechnicalReview:{
            handler (newval, oldVal) {
                if(newval){
                    //console.log('=======',newval)
                    this.formField = JSON.parse(JSON.stringify(newval))
                    this.formField.fcyqtwt = newval.fcyqtwt?newval.fcyqtwt:'无'
                    this.formField.nextNodeDbrList.forEach(item => {
                        item = {
                            value:item.dbrid,
                            label:item.dbr
                        }
                        this.HandledByOptions.push(item)
                    });
                    this.refreshFunction(1)
                }
            },
            immediate: true,
            deep: true
        },
    },
    data(){
        return{
            selectItem:null,
            tabsModeValue:'审查项目',
            formField:{},
            HandledByOptions:[],
            typeSelect:typeSelect,
            YchConstant:YchConstant,
            blobType:blobType,
            routeName:this.$route.name,
            reviewItemsRefresh:null,
            reviewItemsFormItem:[
                {
                    label: '条款',
                    model: 'ftype4',
                    
                },{
                    label: '审查结论',
                    model: 'fjcjl',
                    separateAreas: 'jcxmqxzt'+this.addEdittechnicalReview.fywflcode?this.addEdittechnicalReview.fywflcode:(blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))]),
                    dictionaryType:'审评结论',
                    type:typeSelect,
                },{
                    label: '审查记录',
                    model: 'fscjl',
                },{
                    label: '技术审查结论',
                    model: 'fgjshjl',
                    separateAreas: 'jcxmqxzt'+this.addEdittechnicalReview.fywflcode?this.addEdittechnicalReview.fywflcode:(blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))]),
                    dictionaryType:'技术审查结论',
                    type:typeSelect,
                }
            ],
            reviewItemsConfig:{
                api: assessCheckApi.queryJcxmList,
                rowId: 'id',
                fywflcode:this.addEdittechnicalReview.fywflcode?this.addEdittechnicalReview.fywflcode:(blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))]),
                height:document.body.clientHeight - 220,
                pageSize:1000,
                paramet:{
                    type:'审评项目',
                    sqsxid:this.addEdittechnicalReview?this.addEdittechnicalReview.sqsxid:'',
                    // sfqx:this.addEdittechnicalReview?this.addEdittechnicalReview.sfqx:'',
                }
            },
            reviewItemsColumns:[{
                title: '序号', //列头显示文字
                field: 'fxh',
                width:100,
            }
            ,{
                title: '条款',
                field: 'ftype5',
                // slots: {
                //     // 使用插槽模板渲染
                //     default: 'name_ftype5',
                // },
                width:180,
            },{
                title: '条款号',
                field: 'ftype7',
                slots: {
                    // 使用插槽模板渲染
                    default: 'name_ftype7',
                },
                width:180,
            },{
                title: '审查结论',
                field: 'fjcjl',
                slots: { default: 'name_fjcjl' },
                // titlePrefix:{icon:'vxe-icon-edit'},
                width:120,
            },{
                title: '审查记录',
                field: 'fscjl',
                slots: { default: 'name_fscjl' },
                // titlePrefix:{icon:'vxe-icon-edit'},
            },{
                title: '技术审查内容（提示：光标移除自动保存，并有提示修改成功）',
                field: 'fgjqk',
                slots: { default: 'name_fgjqk' },
                titlePrefix:{icon:'vxe-icon-edit'},
            },{
                title: '技术审查结论',
                field: 'fgjshjl',
                slots: { default: 'name_fgjshjl' },
                titlePrefix:{icon:'vxe-icon-edit'},
            }],
            treeCheckedKeys:[],
            selectedKeys:[],
            treeData:[],
            reviewRecordsId:'',
            fgjqkValue:'',
            fgjqkContent:{},
            fcontentObj:{},
            fcontentVisible:false,
            iframeSrc:'',
            pdfVisible:false,
            optionsData:[],

            activeKeyArr:['1','2','3'],
            refreshTable:null,
            reportConfig:{
                api:assessCheckApi.queryHcyXpList,
                rowId: 'id',
                fywflcode:this.addEdittechnicalReview.fywflcode?this.addEdittechnicalReview.fywflcode:(blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))]),
                height:400,
                autoHidden:true,
                pageSize:100,
                listData:'jsscbgList',
                isPdf:true,
                suffix:{
                    key:'fwjlx',
                    value:'.pdf'
                },
                paramet:{
                    sqsxid:this.addEdittechnicalReview?this.addEdittechnicalReview.sqsxid:''
                }
            },
            reportColumns:[{ 
                type: 'checkbox', 
                width: 60 ,
                fixed: 'left'
            },{
                title: '药品经营企业技术审评审核件', //列头显示文字
                field: 'fwjccmc',
                slots: {
                    // 使用插槽模板渲染
                    default: 'fwjccmc_slots',
                },
            },{
                title: '操作',
                field: 'id',
                slots: {
                    // 使用插槽模板渲染
                    default: 'operation_btn',
                },
                width:750,
                fixed:'right'
            }],
            rectificationConfig:{
                api:assessCheckApi.queryHcyXpList,
                rowId: 'id',
                fywflcode:this.addEdittechnicalReview.fywflcode?this.addEdittechnicalReview.fywflcode:(blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))]),
                height:400,
                autoHidden:true,
                pageSize:100,
                listData:'jczgclyqList',
                isPdf:true,
                suffix:{
                    key:'fwjlx',
                    value:'.pdf'
                },
                paramet:{
                    sqsxid:this.addEdittechnicalReview?this.addEdittechnicalReview.sqsxid:''
                }
            },
            rectificationColumns:[{ 
                type: 'checkbox', 
                width: 60 ,
                fixed: 'left'
            },{
                title: '整改材料名称', //列头显示文字
                field: 'fwjccmc',
                slots: {
                    // 使用插槽模板渲染
                    default: 'fwjccmc_slots',
                },
            },{
                title: '操作',
                field: 'id',
                slots: {
                    // 使用插槽模板渲染
                    default: 'operation_btn',
                },
                width:750,
                fixed:'right'
            }],
            //专家流程
            flowJkPageConfig:{
                api:assessCheckApi.flowJobPage,
                rowId: 'id',
                fywflcode:this.addEdittechnicalReview.fywflcode?this.addEdittechnicalReview.fywflcode:(blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))]),
                height:400,
                autoHidden:true,
                pageSize:100,
                paramet:{
                    sqsxid:this.addEdittechnicalReview.sqsxid
                }
            },
            flowJkPagecolumnsVxe:[{
                title: '事项名称', //列头显示文字
                field: 'fsxmc',
                fixed: 'left',
            },{
                title: '企业名称', //列头显示文字
                field: 'fqymc',
            },{
                    title: '申请单号',
                    field: 'fsqdbh',
            },{
                title: '任务编号',
                field: 'fslbh',
            },{
                title: '接收时间',
                field: 'fslsj',
                slots: {
                    // 使用插槽模板渲染
                    default: 'name_fslsj',
                },
            },{
                title: '环节名称',
                field: 'fhjmc',
            },{
                title: '待办人',
                field: 'fdbr',
            },{
                title: '发送人',
                field: 'ffsrmc',
            },{
                title: '发送时间',
                field: 'ffssj',
                slots: {
                    // 使用插槽模板渲染
                    default: 'name_ffssj',
                },
            },{
                title: '办理状态',
                field: 'fblzt',
                slots: {
                    // 使用插槽模板渲染
                    default: 'name_fblzt',
                },
            },{
                title: '操作',
                field: 'id',
                slots: {
                // 使用插槽模板渲染
                default: 'operation_btn',
                },
                width:260,
                fixed:'right'
            }],
            examinationVisible:false,
            
        }
    },
    watch:{

    },
    computed: {
        editMode(){
            return this.$store.state.permission.editMode
        },
    },
    mounted(){
        getDictListByDictCodeServe({dictCode:'jcxmqxzt'+
        this.addEdittechnicalReview.fywflcode?this.addEdittechnicalReview.fywflcode:(blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))])}).then(res=>{
            //console.log('字典的res',res)
            if(res.code == 200){
                if(res.result.length){
                    // this.optionsData = res.result
                    this.optionsDataChange(res.result,{label:'itemText',value:'itemValue'})
                }
                
            }
        })
        this.getTreeData()//获取审查项目的树形
    },
    methods:{
        examinationOk(){
            this.reviewRecordsBlurEvent({fgjqk:this.fgjqkContent.fgjqk,id:this.reviewRecordsId})
            
        },
        optionsDataChange(dataList,dataType){
            this.optionsData = []
            var newOptionArr = []
            //标识每一项的下标，并且添加到每一项
            dataList.forEach((item,index) => {
                if(!newOptionArr.filter(l=>l.itemIndex === index).length){
                    newOptionArr.push({...item,itemIndex:index})
                }
            });
            for (let i = 0; i <= newOptionArr.length; i++) {//打印的item为数组中的每一个对象
                let item = newOptionArr[i]
                let index = i
                for (let key in item) { //遍历数组中的对象
                    var currentItem = {}
                    if(index === item.itemIndex){
                        currentItem = {
                            label:item[dataType.label],
                            value:item[dataType.value]
                        }
                        if(!this.optionsData.filter(l=>l.label === currentItem.label).length && currentItem.label){
                            this.optionsData.push(currentItem)
                        }
                    }
                    

                }
            }
        },
        manualSuccess(){
            this.refreshTable = Date.now()
        },
        refreshFunction(){

        },
        tableUpdated(){
            var that = this
            this.$nextTick(()=>{
                that.selectItem = Date.now()
            })
            //console.log('表格渲染完成')
        },
        matterTree(data,val) {
            var a = val+1
            for (var i = 0; i < data.length; i++) {
                // 这里面就是你处理数据的地方 
                // data[i].width = '200'
                if (data[i].children && data[i].children.length > 0) {
                // children若不为空数组，则继续 递归调用 本方法
                // data[i].children['name'+i] = data[i].title
                // //console.log('@@data[i].children',data[i].children)
                //建议用父级的key来做 
                let datas ={}
                datas['type'+a] = data[i].title
                datas['key'+a] = data[i].key
                let currentData = {...data[i],children:{}}
                data[i].children = data[i].children.map(item=> {return{...currentData,...item,...datas}})
                this.matterTree(data[i].children,a)
                }
            }
            return data
        },
        getTreeData(){//获取树形
            queryJcxmTreeTypeServe({sqsxid:this.addEdittechnicalReview.sqsxid,type:'审评项目',fywflcode:this.addEdittechnicalReview.fywflcode}).then(res=>{

                if(res.code == 200){
                    this.treeData = this.matterTree(res.result,0)
                    this.selectedKeys = [this.treeData[0].key]
                    this.reviewItemsConfig.paramet = {...this.reviewItemsConfig.paramet,type1:this.treeData[0].title}
                    this.reviewItemsRefresh = Date.now()
                    //console.log('改造后的树形',this.treeData)
                    
                }
            })
        },
        queryAllJsscqx(){
            this.selectedKeys = []
            this.reviewItemsConfig.paramet = {sqsxid:this.addEdittechnicalReview.sqsxid,jsscqx:'yes' ,}
            this.reviewItemsRefresh = Date.now()
            
        },
        queryAllSfqx(){
            this.selectedKeys = []
            this.reviewItemsConfig.paramet = {sqsxid:this.addEdittechnicalReview.sqsxid,sfqx:'yes' ,}
            this.reviewItemsRefresh = Date.now()
        },
        treeSelect(val,item){//选择树
            this.selectedKeys = val
            if(val.length && item.node && item.node._props && item.node._props.dataRef){
                let data = item.node._props.dataRef
                this.reviewItemsConfig.paramet = {
                    sqsxid:this.addEdittechnicalReview.sqsxid,
                    type:'审评项目',
                    // sfqx:this.addEdittechnicalReview?this.addEdittechnicalReview.sfqx:'',
                    type1:data.type1 ?data.type1:data.title,
                    type2:data.type2 ?data.type2:(data.type1?data.title:''),
                    type3:data.type3 ?data.type3:(data.type2?data.title:''),
                    type4:data.type4 ?data.type4:(data.type3?data.title:''),
                    type5:data.type5 ?data.type5:(data.type4?data.title:''),
                    type6:data.type6 ?data.type6:(data.type5?data.title:''),
                    type7:data.type7 ?data.type7:(data.type6?data.title:''),
                    type8:data.type8 ?data.type8:(data.type7?data.title:''),
                    type9:data.type9 ?data.type9:(data.type8?data.title:''),
                }
                this.$refs.reviewItemsRef.searchEvent()
            }
            if(!val.length){
                this.reviewItemsConfig.paramet = {
                    sqsxid:this.addEdittechnicalReview.sqsxid,
                    type:'审评项目',
                    // sfqx:this.addEdittechnicalReview.sfqx?this.addEdittechnicalReview.sfqx:'',
                }
                this.$refs.reviewItemsRef.searchEvent()
            }
        },
        lookOverContent(val){
            this.fcontentObj = {}
            this.fcontentObj = val
            this.fcontentVisible = true
        },
        selectHandleChange(val,row){
            var that = this
            //console.log(val,row)
            updateSqsxJcxmServe({fjcjl:val,id:row.id,fywflcode:this.addEdittechnicalReview.fywflcode}).then(res=>{
                if(res.code == 200){
                    this.$message.success('修改成功')
                }else{
                    this.$message.warning(res.message)
                    
                }
                this.$refs.reviewItemsRef.searchEvent()
            })
        },
        selectFgjshjlChange(val,row){
            updateYpltJcxm({fgjshjl:row.fgjshjl,id:row.id,fywflcode:this.addEdittechnicalReview.fywflcode}).then(res=>{
                if(res.code == 200){
                    this.$message.success('修改成功')
                }else{
                    this.$message.warning(res.message)
                }
                this.$refs.reviewItemsRef.searchEvent()
            })
        },
        reviewRecordsFocusEvent(){},
        reviewRecordsBlurEvent(val){
            //console.log('当前得到了什么？',val)
            var that = this
            if(val.fgjqk && (val.fgjqk !== this.fgjqkValue)){
                updateYpltJcxm({fgjqk:val.fgjqk,id:val.id,fywflcode:that.addEdittechnicalReview.fywflcode}).then(res=>{
                    if(res.code == 200){
                        this.$message.success('修改成功')
                        this.$refs.reviewItemsRef.searchEvent()
                        this.reviewRecordsId = ''
                        this.examinationVisible = false
                    }else{
                        this.$message.warning(res.message)
                        that.$nextTick(() => {
                            that.$refs.userNameInput.focus()
                            that.reviewRecordsFocusEvent()
                        })
                    }
                })
            }else if(this.fgjqkValue && !val.fgjqk){
                this.$confirm({
                    title:'您确认要保存空的吗？',
                    // icon: createVNode(ExclamationCircleOutlined),
                    onOk() {
                        updateYpltJcxm({fgjqk:val.fgjqk,id:val.id,fywflcode:that.addEdittechnicalReview.fywflcode}).then(res=>{
                            if(res.code == 200){
                                that.$message.success('修改成功')
                                that.$refs.reviewItemsRef.searchEvent()
                                that.examinationVisible = false
                                
                            }else{
                                that.$message.warning(res.message)
                                that.$nextTick(() => {
                                    that.$refs.userNameInput.focus()
                                    that.reviewRecordsFocusEvent()
                                })
                            }
                            that.reviewRecordsId = ''
                        })
                        that.reviewRecordsId = ''
                    },
                    onCancel(){
                        that.$refs.reviewItemsRef.searchEvent()
                        that.reviewRecordsId = ''
                    }
                    
                });
            }else{
                this.reviewRecordsId = ''
                this.examinationVisible = false
            }
        },
        reviewRecordsClick(val,isHidden){
            this.fgjqkValue = val.fgjqk
            this.fgjqkContent = val
            this.reviewRecordsId = val.id
            this.examinationVisible = true
            // if(!isHidden){
            //     this.fgjqkValue = val.fgjqk
            //     this.reviewRecordsId = val.id
            //     this.$nextTick(() => {
            //         this.$refs.userNameInput.focus()
            //         this.reviewRecordsFocusEvent()
            //     })
            // }
            
        },
        //生成记录
        generateRecord(val){
            if(val == '发起流程'){
                initJsscbgFlow({sqsxid:this.addEdittechnicalReview.sqsxid,fywflcode:this.addEdittechnicalReview.fywflcode}).then(res=>{
                    if(res.code == 200){
                        this.manualSuccess()
                        this.$message.success(res.message)
                    }else{
                        this.$message.warning(res.message)
                    }
                })
            }else{
                initWjjlServe({sqsxid:this.addEdittechnicalReview.sqsxid,type:val,fywflcode:this.addEdittechnicalReview.fywflcode}).then(res=>{
                    if(res.code == 200){
                        this.manualSuccess()
                        this.$message.success('已生成记录')
                    }else{
                        this.$message.warning(res.message)
                    }
                })
            }
        },
        viewClick(val){
            this.$refs.serverEditingViewRef.getData({id:val.id,fwjlx:val.fwjlx})
            this.$refs.serverEditingViewRef.serverEditingVisible = true
        },
        //查看
        lookOverClick(val){
            getFileTypeServe({id:val.id,fywflcode:this.addEdittechnicalReview.fywflcode}).then(res=>{
                if(res.code == 200){
                    if(res.result == '.pdf'){
                        window.open(
                            bootConfig[process.env.NODE_ENV].locality_ApI+YchConstant.SPZX_SPCY+'/spcySqsxWjjl/getCrossLocalFile?id='+val.id
                        )
                    }else{
                        this.$message.warning('只能查看pdf文件')
                    }
                    
                }
                
            })
            
        },
        producerMould(row,val){
            this.$refs.selectTemplateRef.getSelectTemplate(row,val,this.formField.sqsxid)
            this.$refs.selectTemplateRef.selectTemplateVisible = true
        },
        selectTemplateComplete(){
            this.manualSuccess()
        },
        //重新编辑
        againEdit(val){
            var that = this
            this.$confirm({
                title:'您确认删除已生成的pdf重新编辑文档吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    againEditPdfFile({id:val.id,fywflcode:that.addEdittechnicalReview.fywflcode}).then(res=>{
                        if(res.code == 200){
                            that.$webOffice(
                                `api/spzx-spcy/spcyRsWjmb/openWjjl?id=${res.result.id}`,
                                `api/spzx-spcy/spcyRsWjmb/onLineSaveWjjl?id=${res.result.id}`+`-name=${val.fwjlx1+val.fwjlx}`,
                                `api/spzx-spcy/spcyRsWjmb/saveFileToPdf2?id=${res.result.id}`+`&sqsxid=${that.formField.sqsxid}`,
                                `api/spzx-spcy/spcyRsWjmb/saveFileGzToPdf2?id=${res.result.id}`+`&sqsxid=${that.formField.sqsxid}`,
                                `api/spzx-spcy/spcyRsWjmb/againEditOutPdfFile?id=${res.result.id}`,
                            )
                            that.refreshTable = Date.now()
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                },
                
            });
        },
        //服务端编辑
        serverEdit(val){
            this.$refs.serverEditingRef.getData(val)
        },
        //在线编辑
        producerEdit(val){
            var that = this
            //console.log('在线编辑',val)
            if(val.fwjlx == '.pdf'){
                this.$message.warning('pdf文件无法编辑')
            }else{
                // window.localStorage.setItem('FieldPdf','0')
                // this.modelType = 2
                getFileTypeServe({id:val.id,fywflcode:this.addEdittechnicalReview.fywflcode}).then(res=>{
                    if(res.code == 200){
                        if(res.result !== '.pdf'){
                                that.$webOffice(`api/spzx-spcy/spcyRsWjmb/openWjjl?id=${val.id}`,
                            `api/spzx-spcy/spcyRsWjmb/onLineSaveWjjl?id=${val.id}`+`-name=${val.fwjlx1+val.fwjlx}`,
                                `api/spzx-spcy/spcyRsWjmb/saveFileToPdf2?id=${val.id}`+`&sqsxid=${this.formField.sqsxid}`,
                                `api/spzx-spcy/spcyRsWjmb/saveFileGzToPdf2?id=${val.id}`+`&sqsxid=${this.formField.sqsxid}`,
                                `api/spzx-spcy/spcyRsWjmb/againEditOutPdfFile?id=${val.id}`,
                            )
                        }else{
                            this.refreshTable = Date.now()
                            this.$message.warning('pdf文件无法编辑')
                        }
                        
                    }
                    
                })
                
            }
            
        },
        //方案删除
        producerDelete(val){
            var that = this
            this.$confirm({
                title:'您确认要删除吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    deleteFileByIdServe({id:val.id,fywflcode:that.addEdittechnicalReview.fywflcode}).then(res=>{
                        if(res.code == 200){
                            that.manualSuccess()
                            that.$message.success('删除成功')
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                },
                
            });
            
        },
        producerBeforeUpload(e){
            return false
        },
        producerUpload({file},val){//
            var that = this
            if(typeof file.uid !== 'undefined') {
                // if(file.name.indexOf(".xls") !== -1 || file.name.indexOf(".xlsx") !==-1) {
                    const fileData = new FormData();
                    fileData.append("file",file);
                    fileData.append("fywflcode",this.addEdittechnicalReview.fywflcode?this.addEdittechnicalReview.fywflcode:(blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))]));
                    fileData.append("id",val.id);
                    fileData.append("sqsxid",this.formField.sqsxid);
                    
                    uploadPdfFileById(fileData).then(res => {
                        if(res.code !== 200){
                            that.$message.warning('请上传pdf文件或者联系管理员!')
                        }else{
                            this.manualSuccess()
                            that.$message.success('上传成功')
                        }
                        
                    })
                // }
                
            }
        },
        producerDownload(val){//下载模板
            var that = this
            var fileName = val.fwjccmc 
            let param = { fywflcode:this.addEdittechnicalReview.fywflcode?this.addEdittechnicalReview.fywflcode:(blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))]),id:val.id,sqsxid:this.formField.sqsxid}
            
            getFileTypeServe({id:val.id,fywflcode:this.addEdittechnicalReview.fywflcode}).then(res=>{
                if(res.code == 200){
                    getLocalFileByIdServe(param).then((data) => {
                        if (!data) {
                            that.$message.warning('文件下载失败')
                        return
                        }
                        // if (typeof window.navigator.msSaveBlob !== 'undefined') {
                        //     window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }))
                        // } else {
                            let url = window.URL.createObjectURL(new Blob([data], { type: blobType.type[blobType.suffix.indexOf(val.fwjlx)] }))
                            let link = document.createElement('a')
                            link.style.display = 'none'
                            link.href = url
                            link.setAttribute('download', fileName + res.result)
                            document.body.appendChild(link)
                            link.click()
                            document.body.removeChild(link) //下载完成移除元素
                            window.URL.revokeObjectURL(url) //释放掉blob对象
                        // }
                    })
                }
                
            })
           
            
        },
        timeProcessing(val){
            if(val){
                val = val.slice(0,11)
            }
            return val
        },
        expertProcessReturn(val){
            //console.log(val)
            var that = this
            this.$confirm({
                title:'您确认要退回吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    returnSpBzFlow({jobid:val.jobid,fywflcode:that.addEdittechnicalReview.fywflcode}).then(res=>{
                        if(res.code == 200){
                            that.$message.success(res.message)
                            that.manualSuccess()
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                },
                
            });
        },
        expertProcesstErmination(row,val){
            var that = this
            this.$confirm({
                title:'您确认要终止吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    endFlowJob({jobid:row.jobid,fywflcode:that.addEdittechnicalReview.fywflcode}).then(res=>{
                        if(res.code == 200){
                            that.$message.warning(res.message)
                            that.manualSuccess()
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                    
                },
                
            });
            
        },
    }
}
</script>
<style lang="less">
.segment-content-box{
    .ant-tabs{
        margin-top: 20px;
    }
    .ant-tabs-nav .ant-tabs-tab-active {
        color: #5ca3e5;
        background: #5ca3e5;
        color: #fff;
        border-top-left-radius: 10px;
    }
    .ant-tabs-ink-bar{
        background: #5ca3e5 !important;
    }
    .ant-tabs-tab-active:hover{
        color: #fff !important;
    }
    // .ant-tabs-nav .ant-tabs-tab:hover{
    //     color: #fff !important;
    // }
}
.btn-only{
    .ant-form-item-control-wrapper{
        margin-left: 142px;
        margin-top: 20px;
    }
}
.segment-long-box{
    margin-top: 15px;
    width: 100%;
    .ant-form-item-control-wrapper{
        width: 80%;
    }
    .ant-form-item-children{
        display: flex;
    }
}
.label-box-w{
    .ant-form-item-label{
        width: 142px;
    }
}
.tree-left-box{
    width: 240px;
    padding: 15px;
    height: 480px;
    overflow: auto;
}
.tree-right-box{
    min-width: 1000px;
}

.review-records-box{
    position: absolute;
    left: 0;
    top: 10px;
}
.accompany-form-item{
    position: relative;
}
.select-accompany{
    position: absolute;
    top: 26px;
    width: 183px;
    z-index: 9999;
    background: #fff;
    border-top: 1px solid #e5e5e5;
    border-left: 1px solid #e5e5e5;
    border-right: 1px solid #e5e5e5;
    .select-accompany-item{
        padding-left: 15px;
        border-bottom: 1px solid #e5e5e5;
    }
}
</style>